/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.com.pps.services;

import java.util.ArrayList;
import java.util.List;
import vn.com.pps.dao.IPupilDAO;
import vn.com.pps.entities.Pupil;
import vn.com.pps.web.ui.PupilTableItem;
import vn.com.pps.web.ui.PupilUI;

/**
 *
 * @author Dai
 */
public class PPSService implements IPPSService {

    private IPupilDAO pupilDAO;

    @Override
    public int countPupil() {
        return pupilDAO.getCount();
    }

    public void setPupilDAO(IPupilDAO pupilDAO) {
        this.pupilDAO = pupilDAO;
    }

    @Override
    public ArrayList<PupilTableItem> getPupils() {
        ArrayList<PupilTableItem> pupilTableItems = new ArrayList<PupilTableItem>();
        for (Pupil pupil : pupilDAO.getPupils()) {
            pupilTableItems.add(new PupilTableItem(pupil));
        }
        return pupilTableItems;
    }

    @Override
    public ArrayList<PupilTableItem> getPupils(int pageNo, int pageSize, String whereClause) {
        ArrayList<PupilTableItem> pupilTableItems = new ArrayList<PupilTableItem>();
        for (Pupil pupil : pupilDAO.getPupils(pageNo, pageSize, whereClause).getPageItems()) {
            pupilTableItems.add(new PupilTableItem(pupil));
        }
        return pupilTableItems;
    }

    @Override
    public Pupil getPupil(Integer id) {
        return pupilDAO.getPupil(id);
    }

    @Override
    public int countPupil(String whereClause) {
        return pupilDAO.getCount(whereClause);
    }
    
    

}
